<?php
require_once( 'PHPUnit.php' );
require_once( 'cube/controller.php' );
require_once( 'odal/omsdata.php' );
require_once( 'odal/omsstructure.php' );
using( "brixlent.core", "profile" );
using( "brixlent.core.db", "profilemapper" );

class oms_Test extends PHPUnit_TestCase{
	var $m_oOmsData;
	
	function setup(){
		$this->m_oOmsData = new odal_OmsData();
		$this->m_oOmsData->init( "cube.core.data", "oms11neu", 0 );
	}//setup

	function testMerge(){
		$oOmsStructure1  =& $this->m_oOmsData->getOmsstructureByWhere( 'elm_bookmark = ' . "'MMG-OU'");
//		$this->_displayStructure( $oOmsStructure1 ); 
		$oOmsStructure2  =& $this->m_oOmsData->getOmsstructureByWhere( 'elm_id = 4934' );
		$oCompanyElement =& $oOmsStructure2->getElementById( 4934 ); 
//		$this->_displayStructure( $oOmsStructure2 ); 
		$oOmsStructure1->merge( $oOmsStructure2 );
//		$this->_displayStructure( $oOmsStructure1 );
		
		$oProfile1 =& new core_Profile();
		$this->_setProfileValues( $oProfile1, 'Volker', 'Schubert' );
		$oProfile2 =& new core_Profile();
		$this->_setProfileValues( $oProfile2, 'Werner', 'Anthuber' );
		$oProfileMapper =& new core_ProfileMapper();
		$oProfileMapper->createProfileByStructure( $oOmsStructure1, $oProfile1, 'MMG-OU' );
		$oProfileMapper->createProfileByStructure( $oOmsStructure1, $oProfile2, 'MMG-OU' );
		$oProfileMapper->associateCompanyAndProfile( $oOmsStructure1, 4934, $oProfile1->getId() );
		$oProfileMapper->associateCompanyAndProfile( $oOmsStructure1, 4934, $oProfile2->getId() );
		$this->_displayStructure( $oOmsStructure1 );
		//$this->assertEquals( 'EXPO REAL FORUM', $text );
	}//testGetPropertiesFromDB
	
	function _setProfileValues( &$p_oProfile, $p_firstname, $p_lastname ){
		$p_oProfile->setFirstname( $p_firstname );
		$p_oProfile->setLastname( $p_lastname );
	}//_setProfileValues
	
	function _displayStructure( &$p_oOmsStructure ){
		using( "odal", "xmlvisualizer" );
		echo "<br>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>";
		$xMLVisualizer =& new odal_XMLVisualizer( $p_oOmsStructure );
		$xml = $xMLVisualizer->getOmsStructureAsXML();
		echo $xml;
		echo "<br>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>";
	}//_displayStructure

}//oms_Test
?>
